//
//  CLEditCaseTableViewController.m
//  CareLinkApp_iOS19
//
//  Created by tanky on 16/8/23.
//  Copyright © 2016年 Seven Team. All rights reserved.
//

#import "CLEditCaseTableViewController.h"
#import "CLCaseNoteController.h"

@interface CLEditCaseTableViewController ()

@end

@implementation CLEditCaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadUI];
}

- (void)loadUI{
    self.title = @"病例详情";
    self.diseaseTypeparameter = self.caseDisplayDict[@"diseaseTypeparameter"];
    self.diseaseDetail = self.caseDisplayDict[@"diseaseDetail"];
    self.symptomDes = self.caseDisplayDict[@"symptomDes"];
    self.firstImage = self.caseDisplayDict[@"image"];
    self.updateImages = self.caseDisplayDict[@"updateImages"];
    self.btnName = @"删除病例";
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveData)];
    self.navigationItem.rightBarButtonItem = rightBtn;
}

- (void)saveData{
    if (self.firstImage) {
        [self.addCaseData setObject:self.firstImage forKey:@"image"];
    }else{
        [self.addCaseData setObject:[UIImage imageNamed:@"product_text_logo_nor.png"] forKey:@"image"];
    };
    if (self.diseaseTypeparameter && self.diseaseDetail && self.symptomDes) {
        
        [self.addCaseData setObject:self.diseaseTypeparameter forKey:@"diseaseTypeparameter"];
        [self.addCaseData setObject:self.diseaseDetail forKey:@"diseaseDetail"];
        [self.addCaseData setObject:self.symptomDes forKey:@"symptomDes"];
        NSDate *date = [NSDate date];
        
        NSDateFormatter *date_formatter = [[NSDateFormatter alloc]init];
        
        [date_formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        
        NSString *dateString = [date_formatter stringFromDate:date];
        
        [self.addCaseData setObject:dateString forKey:@"time"];
        
        for (UIViewController *vc in self.navigationController.childViewControllers) {
            if (vc.class == [CLCaseNoteController class]) {
                CLCaseNoteController *caseNoteController = (CLCaseNoteController *)vc;
                caseNoteController.saveDict = self.addCaseData;
                caseNoteController.deleteDict = self.caseDisplayDict;
                [self.navigationController popToViewController:vc animated:YES];
            }
        }
    }else{
        UILabel * tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 225, 120, 30)];
        // 设置提示内容
        [tipLabel setText:@"请将信息填写完整"];
        tipLabel.backgroundColor = [UIColor blackColor];
        tipLabel.layer.cornerRadius = 5;
        tipLabel.layer.masksToBounds = YES;
        tipLabel.textAlignment = NSTextAlignmentCenter;
        tipLabel.textColor = [UIColor whiteColor];
        [self.tableView addSubview:tipLabel];
        [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.tableView).offset(self.tableView.bounds.size.height / 5);
            make.centerX.equalTo(self.tableView);
        }];
        // 设置时间和动画效果
        [UIView animateWithDuration:2.0 animations:^{
            tipLabel.alpha = 0.0;
        } completion:^(BOOL finished) {
            // 动画完毕从父视图移除
            [tipLabel removeFromSuperview];
        }];
    };
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)return2PreView{
    //弹出提示框 是否删除病例
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"是否删除所选病例" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        for (UIViewController *vc in self.navigationController.childViewControllers) {
            if (vc.class == [CLCaseNoteController class]) {
                CLCaseNoteController *caseNoteController = (CLCaseNoteController *)vc;
                caseNoteController.deleteDict = self.caseDisplayDict;
                [self.navigationController popToViewController:vc animated:YES];
            }
        }
     
        
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
